<template>
  <div>
    <!-- 导航栏开始 -->
    <van-nav-bar :border="false">
      <template #left>
        <img src="../assets/image/logo.svg" alt="" @click="goHome" />
      </template>
      <template #right>
        <i class="iconfont icon-yonghuming-copy" @click="getuser"></i>

        <!-- 右侧遮罩层开始 -->
        <van-popup
          overlay
          v-model="showuser"
          position="right"
          :style="{ width: '85%', height: '100%' }"
          :closeable="true"
          close-icon-position="top-right"
          :close-on-click-overlay="false"
        >
          <div class="topLogo">
            <img src="../assets/image/logo.svg" alt="" />
          </div>

          <div class="Navbar-accountDropdownLoggedOut">
            <div class="isLogin" v-if="isLogin">
              <div>欢迎:</div>
              <span>{{ username }}</span>
            </div>
            <div class="Navbar-modalSection" v-else>
              <button @click="goLogin">登录</button>
            </div>

            <div class="Navbar-accountDropdownSupport" v-if="isLogin">
              <van-icon name="setting" />
              <a href="">账户</a>
            </div>
            <div class="Navbar-accountDropdownSupport" v-else>
              <van-icon name="question-o" />
              <a href="">支持</a>
            </div>

            <div class="Navbar-accountDropdownSupport" v-if="isLogin">
              <van-icon name="gift-o" />
              <a href="">我的礼物</a>
            </div>
            <div class="Navbar-accountDropdownSupport" v-else>
              <van-icon name="setting" />
              <a href="">账户</a>
            </div>

            <div class="Navbar-accountDropdownSupport" v-if="isLogin">
              <van-icon name="revoke" />
              <span @click="quitLogin()">注销</span>
            </div>
            <div class="Navbar-accountDropdownSupport" v-else>
              <van-icon name="manager" />
              <span @click="onClickRight">免费注册</span>
            </div>
          </div>
        </van-popup>
        <!-- 右侧遮罩层结束 -->
      </template>
    </van-nav-bar>
    <!-- 导航栏结束 -->

    <!-- 搜索栏开始 -->
    <van-row fixed type="flex" justify="center">
      <van-col span="3" class="liebiao" @click="getLiebiao">
        <img src="../assets/image/liebiao.svg" alt="" />
      </van-col>
      <van-popup
        overlay
        v-model="liebiao"
        position="left"
        :style="{ width: '85%', height: '100%' }"
        :closeable="true"
        close-icon-position="top-left"
        :close-on-click-overlay="false"
      >
        <div class="menu-header">
          <img src="../assets/image/logo.svg" alt="" />
        </div>
        <ul class="menu-container">
          <li @click="goHome">主页</li>
          <li>总览</li>
          <li>周边商城</li>
          <li @click="goWishlist">心愿单</li>
          <li>战网点数</li>
        </ul>
      </van-popup>

      <van-col span="18" offset="1" class="sousuo">
        <van-search
          v-model="value"
          shape="square"
          background="#23252b"
          placeholder="搜索商城"
        />
      </van-col>
    </van-row>
    <!-- 搜索栏结束 -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: "",
      liebiao: false,
      showuser: false,
      username: "",
      isLogin: "",
    };
  },
  mounted() {
    this.username = sessionStorage.getItem("name");
    this.isLogin = sessionStorage.getItem("islogin");
  },
  methods: {
    getLiebiao() {
      this.liebiao = true;
    },
    getuser() {
      this.showuser = true;
    },
    // 登录页
    goLogin() {
      this.$router.push("/login");
    },
    // 退出登录
    quitLogin() {
      sessionStorage.clear();
      this.$store.commit("loginOK", false);
      if (this.$router.options.base == "/") {
        location.reload();
      } else {
        this.$router.push("/");
      }
    },
    // 返回首页
    goHome() {
      this.$router.push("/");
    },
    // 前往注册页
    onClickRight() {
      this.$router.push("/register");
    },
    // 前往心愿单
    goWishlist() {
      if (!this.$store.state.islogin) {
        this.$toast("请先登录");
        this.$router.push("/login");
      } else {
        this.$router.push("/wishlist");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.van-nav-bar {
  margin-top: 16px;
  background-color: #15171e !important;

  .van-nav-bar__content {
    height: 48px !important;

    .van-nav-bar__left {
      img {
        display: inline-block;
        height: 22.2px;
      }
    }

    .van-nav-bar__right {
      i {
        font-size: 20px;
        color: #bebec0;
      }
    }
  }
}

.van-col {
  margin-top: 16px;
  background-color: #23252b;
  height: 52px;
  border-radius: 4px;
}

.van-popup--right {
  background-color: #1a1c23 !important;

  .topLogo {
    box-sizing: border-box;
    width: 100%;
    height: 80px;
    padding: 24px;
    background-color: #15171e;
    display: flex;
    justify-content: center;

    img {
      width: 147px;
    }
  }

  .Navbar-accountDropdownLoggedOut {
    .van-icon {
      font-size: 12px !important;
      margin-right: 5px;
    }

    .isLogin {
      height: 73px;
      padding: 16px;
      box-sizing: border-box;
      border-bottom: 1px solid #36383e;
      display: flex;
      align-items: center;
      div {
        font-size: 20px;
        color: #bfc0c2;
        margin-right: 10px;
      }
      span {
        font-size: 22px;
        line-height: 2;
        color: #add8ff;
      }
    }
    .Navbar-modalSection {
      height: 73px;
      padding: 16px;
      box-sizing: border-box;
      border-bottom: 1px solid #36383e;

      button {
        width: 288px;
        height: 40px;
        background-color: #0074e0;
        color: #fff;
        border-radius: 5px;
        border: 0px;
        font-size: 16px;
      }
    }

    .Navbar-accountDropdownSupport {
      height: 44px;
      box-sizing: border-box;
      margin: 8px;
      padding: 0 8px;
      display: flex;
      align-items: center;

      a,
      span {
        color: #bfc0c2;
        font-size: 12px;
      }
    }
  }
}

.van-popup--left {
  background-color: #1a1c23;
  .menu-header {
    box-sizing: border-box;
    width: 100%;
    height: 80px;
    padding: 24px;
    background-color: #15171e;
    display: flex;
    justify-content: center;

    img {
      width: 147px;
    }
  }

  .menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;

    li {
      width: 304px;
      height: 55px;
      padding: 16px;
      box-sizing: border-box;
      font-size: 14px;
      color: #bfc0c2;

      &:nth-child(3) {
        border-bottom: 1px solid #36383e;
      }
    }
  }
}
</style>
